-Subproject commit 7ba80c5ac4a3f6bc3801bb4ac86fd65a569a07ba
+Subproject commit 713816102b1cb61f45d2306f38e3d95dfdcc8ae1
target_dir: Path,
sources: Vec<SourceId>,
build: Option<String>,
+ unused_keys: Vec<String>,
}
impl Show for Manifest {
target_dir: target_dir.clone(),
sources: sources,
build: build,
+ unused_keys: Vec::new(),
}
}
pub fn get_build<'a>(&'a self) -> Option<&'a str> {
self.build.as_ref().map(|s| s.as_slice())
}
+
+ pub fn add_unused_key(&mut self, s: String) {
+ self.unused_keys.push(s)
+ }
+
+ pub fn get_unused_keys<'a>(&'a self) -> &'a [String] {
+ self.unused_keys.as_slice()
+ }
}
impl Target {
use term;
use term::{Terminal,color};
-use term::color::{Color, BLACK, RED, GREEN};
+use term::color::{Color, BLACK, RED, GREEN, YELLOW};
use term::attr::{Attr, Bold};
use std::io::{IoResult, stderr};
use std::fmt::Show;
pub fn error<T: ToStr>(&mut self, message: T) -> IoResult<()> {
self.err().say(message, RED)
}
+
+ pub fn warn<T: ToStr>(&mut self, message: T) -> IoResult<()> {
+ self.err().say(message, YELLOW)
+ }
}
pub type ShellCallback<'a> = |&mut Shell|:'a -> IoResult<()>;
let package = try!(source.get_root_package());
debug!("loaded package; package={}", package);
+ for key in package.get_manifest().get_unused_keys().iter() {
+ try!(shell.warn(format!("unused manifest key: {}", key)));
+ }
+
let override_ids = try!(source_ids_from_config());
let source_ids = package.get_source_ids();
manifest\n\n{}", e)))
};
- toml_manifest.to_manifest(source_id).map_err(|err| {
+ let pair = try!(toml_manifest.to_manifest(source_id).map_err(|err| {
human(format!("Cargo.toml is not a valid manifest\n\n{}", err))
- })
+ }));
+ let (mut manifest, paths) = pair;
+ match d.toml {
+ Some(ref toml) => add_unused_keys(&mut manifest, toml, "".to_string()),
+ None => {}
+ }
+ return Ok((manifest, paths));
+
+ fn add_unused_keys(m: &mut Manifest, toml: &toml::Value, key: String) {
+ match *toml {
+ toml::Table(ref table) => {
+ for (k, v) in table.iter() {
+ add_unused_keys(m, v, if key.len() == 0 {
+ k.clone()
+ } else {
+ key + "." + k.as_slice()
+ })
+ }
+ }
+ toml::Array(ref arr) => {
+ for v in arr.iter() {
+ add_unused_keys(m, v, key.clone());
+ }
+ }
+ _ => m.add_unused_key(key),
+ }
+ }
+
+
}
pub fn parse(toml: &str, file: &str) -> CargoResult<toml::Table> {
(Some(string.clone()), SourceId::for_central())
},
DetailedDep(ref details) => {
- let reference = details.branch.as_ref().map(|b| b.clone())
- .or_else(|| details.tag.as_ref().map(|t| t.clone()))
- .or_else(|| details.rev.as_ref().map(|t| t.clone()))
+ let reference = details.branch.clone()
+ .or_else(|| details.tag.clone())
+ .or_else(|| details.rev.clone())
.unwrap_or_else(|| "master".to_str());
let new_source_id = match details.git {
}
let project = self.project.as_ref().or_else(|| self.package.as_ref());
- let project = try!(project.require(|| human("No `package` or `project` section found.")));
+ let project = try!(project.require(|| {
+ human("No `package` or `project` section found.")
+ }));
+ let pkgid = try!(project.to_package_id(source_id.get_location()));
+ let summary = Summary::new(&pkgid, deps.as_slice());
Ok((Manifest::new(
- &Summary::new(&try!(project.to_package_id(source_id.get_location())),
- deps.as_slice()),
+ &summary,
targets.as_slice(),
&Path::new("target"),
sources,
pub fn basic_bin_manifest(name: &str) -> String {
format!(r#"
- [project]
+ [package]
name = "{}"
version = "0.5.0"
assert!(file0.ends_with(os::consts::DLL_SUFFIX) ||
file1.ends_with(os::consts::DLL_SUFFIX));
})
+
+test!(unused_keys {
+ let mut p = project("foo");
+ p = p
+ .file("Cargo.toml", r#"
+ [project]
+
+ name = "foo"
+ version = "0.5.0"
+ authors = ["wycats@example.com"]
+ bulid = "foo"
+
+ [[lib]]
+
+ name = "foo"
+ "#)
+ .file("src/foo.rs", r#"
+ pub fn foo() {}
+ "#);
+ assert_that(p.cargo_process("cargo-build"),
+ execs().with_status(0)
+ .with_stderr("unused manifest key: project.bulid\n"));
+
+ let mut p = project("bar");
+ p = p
+ .file("Cargo.toml", r#"
+ [project]
+
+ name = "foo"
+ version = "0.5.0"
+ authors = ["wycats@example.com"]
+
+ [[lib]]
+
+ name = "foo"
+ build = "foo"
+ "#)
+ .file("src/foo.rs", r#"
+ pub fn foo() {}
+ "#);
+ assert_that(p.cargo_process("cargo-build"),
+ execs().with_status(0)
+ .with_stderr("unused manifest key: lib.build\n"));
+})